package com.zpark.se.string;

public class StringBuilderDemo01 {
    public static void main(String[] args) {
        // 创建StringBuilder对象
        StringBuilder sb = new StringBuilder();
        StringBuilder builder = new StringBuilder(30);
        StringBuilder b1 = new StringBuilder("Java");

        // StringBuilder类与StringBuffer类提供的方法完全一致
        /*
        注意：StringBuffer 是线程安全的，而 StringBuilder 则没有实现线程安全功能
        StringBuilder执行效率比StringBuffer高
         */

        // 字符串拼接
        String s = "Java";
        // 将字符串添加到StringBuffer对象当中
        sb.append(s);
        // 获取系统时间戳
        long start = System.currentTimeMillis();
        for (int i = 0; i < 1000000; i++) {
            // s += s;  // s = s + s;
            sb.append(s);
        }
        // 再次获取系统时间戳
        long end = System.currentTimeMillis();
        System.out.println("程序耗时：" + (end - start) + "毫秒");
    }
}
